package com.lgq.cfw.controller.permission;

import com.lgq.cfw.bean.message.Message;
import com.lgq.cfw.service.RoleAndUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Lin
 * @date 2019-02-09 15:26
 **/
@RestController
@RequestMapping(value = "/permission/roleAndUser")
public class RoleAndUserController {
  @Autowired
  RoleAndUserService roleAndUserService;


  /**
   * 保存用户的角色信息
   * @param userId 用户id
   * @param selectedId 被选中的角色id
   * @return 处理信息
   */
  @RequestMapping(value = "/save",method = RequestMethod.POST)
  public Message saveRole(@RequestParam(value = "userId")Integer userId,
      @RequestParam(value = "selectedId") String selectedId){
    roleAndUserService.save(userId,selectedId);
    return Message.success("处理成功",null);
  }

  /**
   * 删除用户的角色信息
   * @param userId 用户id
   * @param selectedId 被选中的角色id
   * @return 处理信息
   */
  @RequestMapping(value = "/delete",method = RequestMethod.POST)
  public Message deleteRole(@RequestParam(value = "userId") Integer userId,
      @RequestParam(value = "selectedId") String selectedId){
    roleAndUserService.delete(userId,selectedId);
    return Message.success("处理成功",null);
  }
}
